package com.cyy;

import com.cyy.base.util.JwtUtils;
import com.cyy.freemarker.CurrentUserSettingGetter;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;

import java.util.Map;

/**
 * exclude禁用SpringSecurity认证
 */
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
public class AdminApplication {

    public static void main(String[] args) {
        SpringApplication.run(AdminApplication.class, args);
    }

    @Bean
    public JwtUtils jwtUtils(){
        return new JwtUtils();
    }

    @Bean
    public BCryptPasswordEncoder bCryptPasswordEncoder(){
        return new BCryptPasswordEncoder();
    }

    @Bean
    public CommandLineRunner customFreemarker(FreeMarkerViewResolver viewResolver){
        return new CommandLineRunner() {
            @Override
            public void run(String... args) throws Exception {
                //添加自定义解析器
                Map map = viewResolver.getAttributesMap();
                map.put("currentUserSetting",new CurrentUserSettingGetter());
            }
        };
    }
}
